<!DOCTYPE html>
<html style="max-width:720px;min-height: 100%;">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
    <meta name="format-detection" content="telephone=no">
    <title>获取推广人注册链接</title>
    <link rel="stylesheet" href="__PUBLIC__/portal/share/css/hui.css">
    <link rel="stylesheet" href="__PUBLIC__/portal/share/css/style.css">
    <script src="__PUBLIC__/portal/share/js/com.js"></script>
    <script src="__PUBLIC__/portal/share/js/hui.js"></script>
    <script src="__PUBLIC__/portal/share/js/template-web.js"></script>
</head>
<body>
<!--正文区域-->
<!--输入验证码的弹框-->
<div id="maKuang" style="display:none">
    <div class="top">
        <span class="title">获取的网站信息</span>
        <div class="inputArea" id="str">

        </div>
    </div>
</div>
<!--遮罩层-->
<div id="zhezhao" style="display:none"></div>


<div style="background: no-repeat center center none;background-size: cover" class="w100per h100per" id="bgcontain">
    <div>
        <img src="/mobile/themes/mall/default/styles/share/img/bg.jpg"  alt="">
    </div>
    <div id="contain"></div>
</div>
<script type="text/html" id="tpl">
    <div class="pad_l10 pad_r10 pad_b16">
        <div class="bdr8 pad_l10 pad_r10 bgcfff bd_allred">
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table">
                    <div class="fs13 c333 wem6">
                        <div class="pad_l10" style="font-size: 16px;">手机号 </div>
                    </div>
                    <div><input class="fs13 w100per" type="number" placeholder="请输入手机号" name="phone"></div>
                </div>
            </div>
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table" style="">
                    <div class="fs13 c333 wem6">
                        <div class="pad_l10">验证码</div>
                    </div>
                    <div><input class="fs13 w100per" type="number" placeholder="请输入短信验证码" name="yzm"></div>
                    <div class="wem7 txt_right">
                        <a href="javascript:;" class="bgcred bdr4 wem6 txt_center inblock cfff fs13" id="sendma">获取验证码</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="pad10">
        <a href="javascript:;" id="submitbtn" class="cfff fs15 txt_center bgcred bdr4 pad_t10 pad_b10 block">获取推广人注册链接</a>
    </div>
</script>
<script src="//cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/mobile/themes/mall/default/styles/share/js/layer/layer.js"></script>
<script>
    var data={
        tel:'',
        code:''
    };
    var invite_code = '';

    function renderhtml(){
        document.getElementById('contain').innerHTML=template('tpl', data);
    }
    data.tel=Getvariable('phone');
    renderhtml();
    pre_loading_txt(100);

    document.getElementById('bgcontain').style.height='650px';



    //点击获取验证码
    $('#sendma').on('click',function(){
        sendmafun();
    });

    //发送验证码
    var sendmaobj=document.getElementById('sendma');
    function sendmafun(){
        if(sendmaobj.innerHTML=='获取验证码' || sendmaobj.innerHTML=='重新发送'){
            var phone=document.getElementsByName('phone')[0].value;
            if(phone==''){
                layer.msg('请输入手机号');
                return false;
            }
            if(!/^1[3|4|5|6|7|8|9]\d{9}$/.test(phone)){
                layer.msg('手机号不正确');
                return false;
            }
            //发送短信接口
            $.post(
                "{:U('api/Index/promotersCode')}",
                {
                    phone_mob:phone,
                },
                function(res){
                    res = JSON.parse(res);
                    if (res.code == 1) {
                        layer.msg('发送成功！');
                        daojishi();
                    } else
                        layer.msg(res.msg);
                    return false;
                },
            );
        }
    }

    var timer=null;
    var timezhi=60;
    var timecurr=timezhi;
    function daojishi(){
        console.log('enter')
        timecurr=timezhi;
        sendmaobj.innerHTML=timecurr+'s';

        timer=setInterval(function(){
            if(timecurr>1){
                timecurr--;
                sendmaobj.innerHTML=timecurr+'s';
            }else{
                clearInterval(timer);
                timer=null;
                sendmaobj.innerHTML='重新发送';
            }
        },1000);
    }


    //点击注册
    $('#submitbtn').on('click',function(){
        var phone=document.getElementsByName('phone')[0].value;
        var code=document.getElementsByName('yzm')[0].value;
        if(phone==''){
            layer.msg('请输入手机号');
            return false;
        }
        if(code==''){
            layer.msg('请输入验证码');
            return false;
        }
        if(!/^1[3|4|5|6|7|8|9]\d{9}$/.test(phone)){
            layer.msg('手机号不正确');
            return false;
        }
        var copyBtn = document.querySelector('.copy');

        //发送短信接口
        $.post(
            "{:U('Api/index/index')}",
            {
                phone_mob:phone,
                msg_code:code,
            },
            function(res){
                res = JSON.parse(res);
                if (res.code == 1) {
                    layer.msg('申请成功！',function(){
                        window.location.href = res.data.url;
                    })
                } else
                    layer.msg(res.msg);
                return false;
            },
        );
    });


    // function copytext(html) {
    //     var oInput = document.createElement('input');
    //     oInput.value = html;
    //     document.body.appendChild(oInput);
    //     // oInput.select();
    //     selectText(oInput)
    //     document.execCommand("Copy");
    //     oInput.className = 'oInput';
    //     oInput.style.display = 'none';
    //     alert('链接已复制到剪贴板！');
    // }
    // function selectText(oInput) {
    //     if(oInput.createTextRange) {//ie
    //         oInput.select();
    //     }else{//firefox/chrome
    //         oInput.setSelectionRange(0, oInput.value.length);
    //         oInput.focus();
    //     }
    // }
</script>
</body>
</html>
